class checksum {

    public static int codeChecksum(String code, boolean isEAN) {
	int sum = 0;
	int modval = 0;

	for (int x = 0; x < code.length(); ++x) {

	    int digit = charToInt(code.charAt(x));

	    if (digit >= 10) {

		return 0;
	    }

	    modval = 1;

	    if (x % 2 == 1 && isEAN) {
		modval = 3;

	    }else if (x % 2 == 0 && !isEAN){
		modval = 4;

	    }

	    sum += (digit * modval);

	}

	if (isEAN) {
	    int modsum = sum % 10;
	    int digit = 10 - modsum;
	    if (digit == 10) digit = 0;

	    return digit;
	}

	return sum % 90;
    }

    public static boolean validSticky(String code) {

	if (code == null || code == "" || code.length() != 13) return false;

	String mainnum = code.substring(1, code.length() - 1);
	int chk1 = charToInt(code.charAt(0));
	int chk2 = charToInt(code.charAt(code.length()-1));

	if (chk1 > 10 || chk2 > 10) return false;

	int sbchk = codeChecksum(mainnum, false);
	int frontnum, backnum;

	if (sbchk < 10){
	    frontnum = sbchk;
	    backnum = 0;
	} else {
	    String str = String.valueOf(sbchk);

	    frontnum = charToInt(str.charAt(1));
	    backnum = charToInt(str.charAt(0));
	}

	if (chk1 != frontnum) return false;

	int eanchk = codeChecksum(String.valueOf(frontnum)+String.valueOf(mainnum), true);

	if (eanchk == backnum) backnum++;

	if (chk2 != backnum) return false;

	return true;
    }


    public static int charToInt(char chr) {

	return (int)chr-48;
    }
    
    """

    public static void main (String args[]) {

	System.out.println(checksum.validSticky("6214788223642"));

    }

    """

}
